package com.farmer.controller;

import com.farmer.pojo.Comment;
import com.farmer.pojo.Goods;
import com.farmer.service.CommentService;
import com.farmer.utils.Result;
import com.farmer.utils.ResultCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("comment")
@CrossOrigin
public class CommentController {
    @Autowired
    private CommentService commentService;

    @PostMapping("add")
    public Result add(@RequestHeader String token,@RequestBody Comment comment) {
        Result result = commentService.add(token,comment);
        return result;
    }

    @DeleteMapping("delete")
    public Result delete(@RequestParam Integer id) {
        Result result = commentService.delete(id);
        return result;
    }
    @DeleteMapping("delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids){
        Result result = commentService.deleteBatch(ids);
        return result;
    }

    @PutMapping("update")
    public Result update(@RequestBody Comment comment) {
        Result result = commentService.update(comment);
        return result;
    }

    @GetMapping("getById")
    public Result getById(@RequestParam Integer id) {
        Result result = commentService.getById(id);
        return result;
    }
//
//    @GetMapping("getByPolicyId")
//    public Result getByPolicyId(Integer id) {
//     Result result = commentService.getByPolicyId(id);
//     return result;
//    }

//    后台管理员展示所有评论
    @GetMapping("getAll")
    public Result getAll() {
        Result result = commentService.getAll();
        return result;
    }

    @GetMapping("getByTitleLike")
    public Result getByTitleLike(@RequestParam String content){
        Result result = commentService.getByTitleLike(content);
        return result;
    }

    /*
   /* 前台用户返回树形评论结构*/
    @RequestMapping("/list")
    public Result list(){
        List<Comment> list = commentService.listTree();
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("page")
    public Result page(@RequestParam(defaultValue = "1") Integer pageNum,
                       @RequestParam(defaultValue = "10") Integer pageSize) {
        Result result=commentService.page(pageNum,pageSize);
        return result;
    }
}
